package com.doyens.gmall.product.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.doyens.gmall.common.result.Result;
import com.doyens.gmall.model.product.BaseTrademark;
import com.doyens.gmall.product.service.BaseTrademarkService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/admin/product/baseTrademark")
public class BaseTrademarkController {
    @Autowired
    private BaseTrademarkService baseTrademarkService;

    @GetMapping("/{page}/{limit}")
    public Result getBaseTrademarkList(@PathVariable("page")Long page,
                                       @PathVariable("limit")Long limit){
        Page<BaseTrademark> baseTrademarkPage = new Page<>(page,limit);

        IPage iPage =baseTrademarkService.getBaseTrademarkList(baseTrademarkPage);
        return Result.ok(iPage);
    }

    @PostMapping("save")
    public Result saveTradeMark(@RequestBody BaseTrademark trademark){
        baseTrademarkService.save(trademark);
        return Result.ok();
    }
    @DeleteMapping("/remove/{id}")
    public Result removeTradeMark(@PathVariable("id") Long trademarkId){
        baseTrademarkService.removeById(trademarkId);
        return Result.ok();
    }
    @GetMapping("/get/{id}")
    public Result getTrademark(@PathVariable("id") Long trademarkId){
        BaseTrademark baseTrademark = baseTrademarkService.getById(trademarkId);
        return Result.ok(baseTrademark);
    }
    @PutMapping("/update")
    public Result update(@RequestBody BaseTrademark baseTrademark){
        baseTrademarkService.updateById(baseTrademark);
        return Result.ok();
    }

    @GetMapping("/getTrademarkList")
    public Result getTrademarkList(){
        List<BaseTrademark> list = baseTrademarkService.list(null);
        return Result.ok(list);
    }

}
